data_by_decade<- function(dataset){
dataset$decade <- cut(dataset$year, seq(1950,2010,10),labels = as.character(seq(1950,2000,10)))
return(dataset)
}
fun_continents <- function(continent, decade) {
a <- gapminder[which(gapminder$continent == continent & gapminder$decade == decade),]
stats <- c(min = min(a$lifeExp), max =max( a$lifeExp),
mean = mean(a$lifeExp), median = median(a$lifeExp),
IQR = quantile(a$lifeExp, 0.75) - quantile(a$lifeExp, 0.25))
return(stats)
}
fun_continents( "Africa", 1950)
## Warning: Unknown or uninitialised column: 'decade'.
## Warning in min(a$lifeExp): no non-missing arguments to min; returning Inf
## Warning in max(a$lifeExp): no non-missing arguments to max; returning -Inf
## min max mean median IQR.75%
## Inf -Inf NaN NA NA
gapminder <- data_by_decade(gapminder)
continentdata <- c()
sta <- c()
for(continent in levels(gapminder$continent)) {
for(decade in levels(gapminder$decade)) {
continentdata <- rbind(continentdata, c(continent, decade))
sta <- rbind(sta, fun_continents(continent, decade ))
}
}
continentdata
## [,1] [,2]
## [1,] "Africa" "1950"
## [2,] "Africa" "1960"
## [3,] "Africa" "1970"
## [4,] "Africa" "1980"
## [5,] "Africa" "1990"
## [6,] "Africa" "2000"
## [7,] "Americas" "1950"
## [8,] "Americas" "1960"
## [9,] "Americas" "1970"
## [10,] "Americas" "1980"
## [11,] "Americas" "1990"
## [12,] "Americas" "2000"
## [13,] "Asia" "1950"
## [14,] "Asia" "1960"
## [15,] "Asia" "1970"
## [16,] "Asia" "1980"
## [17,] "Asia" "1990"
## [18,] "Asia" "2000"
## [19,] "Europe" "1950"
## [20,] "Europe" "1960"
## [21,] "Europe" "1970"
## [22,] "Europe" "1980"
## [23,] "Europe" "1990"
## [24,] "Europe" "2000"
## [25,] "Oceania" "1950"
## [26,] "Oceania" "1960"
## [27,] "Oceania" "1970"
## [28,] "Oceania" "1980"
## [29,] "Oceania" "1990"
## [30,] "Oceania" "2000"
sta
## min max mean median IQR.75%
## [1,] 30.000 58.089 40.20092 39.9890 6.51375
## [2,] 32.767 61.557 44.32699 43.9890 7.95300
## [3,] 35.400 67.064 48.51568 48.1205 9.14750
## [4,] 38.445 71.913 52.46883 51.5220 11.47125
## [5,] 23.599 74.772 53.61392 52.6000 12.32125
## [6,] 39.193 76.442 54.06563 52.4060 11.90725
## [7,] 37.579 69.960 54.62006 55.1540 16.43325
## [8,] 43.428 72.130 59.40484 60.3165 12.82300
## [9,] 46.714 74.210 63.39324 65.3720 10.41200
## [10,] 51.461 76.860 67.15978 68.1625 8.27450
## [11,] 55.089 78.610 70.35942 70.7315 5.60250
## [12,] 58.137 80.653 73.01508 72.8275 5.56150
## [13,] 28.801 67.840 47.81647 45.7770 13.72900
## [14,] 31.997 71.430 53.11343 51.6300 14.01075
## [15,] 31.220 75.380 58.46491 59.3750 12.13875
## [16,] 39.854 78.670 63.73456 64.8205 10.69550
## [17,] 41.674 80.690 67.27886 69.0085 10.77300
## [18,] 42.129 82.603 69.98118 71.6570 9.87675
## [19,] 43.585 73.470 65.55578 66.8350 7.47875
## [20,] 52.098 74.160 69.13842 70.0200 3.61550
## [21,] 57.005 76.110 71.35640 71.1400 3.17500
## [22,] 61.036 77.410 73.22428 74.0500 4.40500
## [23,] 66.146 79.390 74.97263 75.8350 4.97725
## [24,] 70.845 81.757 77.17460 78.1770 4.84150
## [25,] 69.120 70.330 69.77500 69.8250 0.95500
## [26,] 70.930 71.520 71.19750 71.1700 0.25250
## [27,] 71.890 73.490 72.38250 72.0750 0.61750
## [28,] 73.840 76.320 74.80500 74.5300 0.93500
## [29,] 76.330 78.830 77.56750 77.5550 0.63250
## [30,] 79.110 81.235 80.22975 80.2870 0.65575
s <- data.frame(continentdata, sta )
names(s)[1] <- "continent"
names(s)[2] <- "decade"
s
## continent decade min max mean median IQR.75.
## 1 Africa 1950 30.000 58.089 40.20092 39.9890 6.51375
## 2 Africa 1960 32.767 61.557 44.32699 43.9890 7.95300
## 3 Africa 1970 35.400 67.064 48.51568 48.1205 9.14750
## 4 Africa 1980 38.445 71.913 52.46883 51.5220 11.47125
## 5 Africa 1990 23.599 74.772 53.61392 52.6000 12.32125
## 6 Africa 2000 39.193 76.442 54.06563 52.4060 11.90725
## 7 Americas 1950 37.579 69.960 54.62006 55.1540 16.43325
## 8 Americas 1960 43.428 72.130 59.40484 60.3165 12.82300
## 9 Americas 1970 46.714 74.210 63.39324 65.3720 10.41200
## 10 Americas 1980 51.461 76.860 67.15978 68.1625 8.27450
## 11 Americas 1990 55.089 78.610 70.35942 70.7315 5.60250
## 12 Americas 2000 58.137 80.653 73.01508 72.8275 5.56150
## 13 Asia 1950 28.801 67.840 47.81647 45.7770 13.72900
## 14 Asia 1960 31.997 71.430 53.11343 51.6300 14.01075
## 15 Asia 1970 31.220 75.380 58.46491 59.3750 12.13875
## 16 Asia 1980 39.854 78.670 63.73456 64.8205 10.69550
## 17 Asia 1990 41.674 80.690 67.27886 69.0085 10.77300
## 18 Asia 2000 42.129 82.603 69.98118 71.6570 9.87675
## 19 Europe 1950 43.585 73.470 65.55578 66.8350 7.47875
## 20 Europe 1960 52.098 74.160 69.13842 70.0200 3.61550
## 21 Europe 1970 57.005 76.110 71.35640 71.1400 3.17500
## 22 Europe 1980 61.036 77.410 73.22428 74.0500 4.40500
## 23 Europe 1990 66.146 79.390 74.97263 75.8350 4.97725
## 24 Europe 2000 70.845 81.757 77.17460 78.1770 4.84150
## 25 Oceania 1950 69.120 70.330 69.77500 69.8250 0.95500
## 26 Oceania 1960 70.930 71.520 71.19750 71.1700 0.25250
## 27 Oceania 1970 71.890 73.490 72.38250 72.0750 0.61750
## 28 Oceania 1980 73.840 76.320 74.80500 74.5300 0.93500
## 29 Oceania 1990 76.330 78.830 77.56750 77.5550 0.63250
## 30 Oceania 2000 79.110 81.235 80.22975 80.2870 0.65575
From the table, we can see the life expectancy is increasing by decades for each continent. But the IQR for developing countries, like in Asia increase first and then decrease a littel bit. And for Europe and Americas, the IQR doesn’t change a lot, it’s steady.
Now, we can consider plots to look into this further.
Europe <- subset(gapminder, continent == "Europe")
Africa <- subset(gapminder, continent == "Africa")
Asia <- subset(gapminder, continent == "Asia")
Americas <- subset(gapminder, continent == "Americas")
Oceania <- subset(gapminder, continent == "Oceania")
aggregate(lifeExp~continent, gapminder, min)
## continent lifeExp
## 1 Africa 23.599
## 2 Americas 37.579
## 3 Asia 28.801
## 4 Europe 43.585
## 5 Oceania 69.120
aggregate(lifeExp~continent, gapminder, max)
## continent lifeExp
## 1 Africa 76.442
## 2 Americas 80.653
## 3 Asia 82.603
## 4 Europe 81.757
## 5 Oceania 81.235
aggregate(lifeExp~continent, gapminder, mean)
## continent lifeExp
## 1 Africa 48.86533
## 2 Americas 64.65874
## 3 Asia 60.06490
## 4 Europe 71.90369
## 5 Oceania 74.32621
aggregate(lifeExp~continent, gapminder, median)
## continent lifeExp
## 1 Africa 47.7920
## 2 Americas 67.0480
## 3 Asia 61.7915
## 4 Europe 72.2410
## 5 Oceania 73.6650
aggregate(lifeExp~continent, gapminder, IQR)
## continent lifeExp
## 1 Africa 12.0390
## 2 Americas 13.2895
## 3 Asia 18.0790
## 4 Europe 5.8805
## 5 Oceania 6.3475
filter(gapminder,(continent=="Europe" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Europe" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Europe" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Europe" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Europe" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Africa" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Africa" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Africa" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Africa" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Africa" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Asia" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Asia" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Asia" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Asia" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Asia" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Americas" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Americas" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Americas" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Americas" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Americas" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
fun_gdp <- function(continent, decade) {
a <- gapminder[which(gapminder$continent == continent & gapminder$decade == decade),]
stats2 <- c(min = min(a$gdpPercap), max =max( a$gdpPercap),
mean = mean(a$gdpPercap), median = median(a$gdpPercap),
IQR = quantile(a$gdpPercap, 0.75) - quantile(a$gdpPercap, 0.25))
return(stats2)
}
fun_gdp("Africa",1950)
## min max mean median IQR.75%
## 298.8462 5487.1042 1318.9043 1024.0230 950.0916
gap <- data_by_decade(gapminder)
continentgdp <- c()
sta2<- c()
for(continent in levels(gap$continent)) {
for(decade in levels(gap$decade)) {
continentgdp <- rbind(continentgdp, c(continent, decade))
sta2 <- rbind(sta2, fun_gdp(continent, decade ))
}
}
continentgdp
## [,1] [,2]
## [1,] "Africa" "1950"
## [2,] "Africa" "1960"
## [3,] "Africa" "1970"
## [4,] "Africa" "1980"
## [5,] "Africa" "1990"
## [6,] "Africa" "2000"
## [7,] "Americas" "1950"
## [8,] "Americas" "1960"
## [9,] "Americas" "1970"
## [10,] "Americas" "1980"
## [11,] "Americas" "1990"
## [12,] "Americas" "2000"
## [13,] "Asia" "1950"
## [14,] "Asia" "1960"
## [15,] "Asia" "1970"
## [16,] "Asia" "1980"
## [17,] "Asia" "1990"
## [18,] "Asia" "2000"
## [19,] "Europe" "1950"
## [20,] "Europe" "1960"
## [21,] "Europe" "1970"
## [22,] "Europe" "1980"
## [23,] "Europe" "1990"
## [24,] "Europe" "2000"
## [25,] "Oceania" "1950"
## [26,] "Oceania" "1960"
## [27,] "Oceania" "1970"
## [28,] "Oceania" "1980"
## [29,] "Oceania" "1990"
## [30,] "Oceania" "2000"
sta2
## min max mean median IQR.75%
## [1,] 298.8462 5487.104 1318.904 1024.023 950.0916
## [2,] 355.2032 18772.752 1824.221 1191.555 1104.8081
## [3,] 464.0995 21951.212 2462.777 1402.376 1724.7493
## [4,] 389.8762 17364.275 2382.131 1286.173 1983.9259
## [5,] 312.1884 14722.842 2330.285 1179.883 2069.0063
## [6,] 241.1659 13206.485 2844.209 1307.562 2826.6352
## [7,] 1397.7171 14847.127 4347.553 3266.944 2205.0266
## [8,] 1452.0577 19530.366 5284.898 4549.084 2799.6370
## [9,] 1654.4569 24072.632 6921.671 5490.198 3124.1509
## [10,] 1823.0160 29884.350 7650.069 6397.723 4300.9379
## [11,] 1341.7269 35767.433 8467.118 6813.664 4848.2282
## [12,] 1201.6372 42951.653 10145.354 7382.469 5542.2684
## [13,] 331.0000 113523.133 5491.608 1497.727 2297.9368
## [14,] 349.0000 95458.112 5850.271 1852.401 4085.0329
## [15,] 357.0000 109347.867 7989.391 2850.723 8539.1421
## [16,] 385.0000 33693.175 7521.181 4106.509 11165.1958
## [17,] 347.0000 40300.620 9236.892 3685.722 15728.0982
## [18,] 611.0000 47306.990 11323.559 4287.633 18938.5251
## [19,] 973.5332 17909.490 6312.035 5730.677 4956.2819
## [20,] 1709.6837 22966.144 9254.655 8463.000 6811.9320
## [21,] 2860.1698 27195.113 13381.777 13044.562 8352.9485
## [22,] 3630.8807 31540.975 16416.104 15995.703 9922.0911
## [23,] 2497.4379 41283.164 18069.175 18122.048 16830.2216
## [24,] 4604.2117 49357.190 23383.107 26653.335 20705.2445
## [25,] 10039.5956 12247.395 10948.304 10753.113 846.7554
## [26,] 12217.2269 14526.125 13595.737 13819.798 1543.4051
## [27,] 16046.0373 18334.198 16850.645 16511.174 988.2239
## [28,] 17632.4104 21888.889 19501.375 19242.100 1416.4832
## [29,] 18363.3249 26997.937 22459.111 22237.590 3939.4177
## [30,] 23189.8014 34435.367 28374.483 27936.382 6938.4507
s2 <- data.frame(continentgdp,sta2)
names(s2)[1] <- "continent"
names(s2)[2] <- "decade"
s2
## continent decade min max mean median IQR.75.
## 1 Africa 1950 298.8462 5487.104 1318.904 1024.023 950.0916
## 2 Africa 1960 355.2032 18772.752 1824.221 1191.555 1104.8081
## 3 Africa 1970 464.0995 21951.212 2462.777 1402.376 1724.7493
## 4 Africa 1980 389.8762 17364.275 2382.131 1286.173 1983.9259
## 5 Africa 1990 312.1884 14722.842 2330.285 1179.883 2069.0063
## 6 Africa 2000 241.1659 13206.485 2844.209 1307.562 2826.6352
## 7 Americas 1950 1397.7171 14847.127 4347.553 3266.944 2205.0266
## 8 Americas 1960 1452.0577 19530.366 5284.898 4549.084 2799.6370
## 9 Americas 1970 1654.4569 24072.632 6921.671 5490.198 3124.1509
## 10 Americas 1980 1823.0160 29884.350 7650.069 6397.723 4300.9379
## 11 Americas 1990 1341.7269 35767.433 8467.118 6813.664 4848.2282
## 12 Americas 2000 1201.6372 42951.653 10145.354 7382.469 5542.2684
## 13 Asia 1950 331.0000 113523.133 5491.608 1497.727 2297.9368
## 14 Asia 1960 349.0000 95458.112 5850.271 1852.401 4085.0329
## 15 Asia 1970 357.0000 109347.867 7989.391 2850.723 8539.1421
## 16 Asia 1980 385.0000 33693.175 7521.181 4106.509 11165.1958
## 17 Asia 1990 347.0000 40300.620 9236.892 3685.722 15728.0982
## 18 Asia 2000 611.0000 47306.990 11323.559 4287.633 18938.5251
## 19 Europe 1950 973.5332 17909.490 6312.035 5730.677 4956.2819
## 20 Europe 1960 1709.6837 22966.144 9254.655 8463.000 6811.9320
## 21 Europe 1970 2860.1698 27195.113 13381.777 13044.562 8352.9485
## 22 Europe 1980 3630.8807 31540.975 16416.104 15995.703 9922.0911
## 23 Europe 1990 2497.4379 41283.164 18069.175 18122.048 16830.2216
## 24 Europe 2000 4604.2117 49357.190 23383.107 26653.335 20705.2445
## 25 Oceania 1950 10039.5956 12247.395 10948.304 10753.113 846.7554
## 26 Oceania 1960 12217.2269 14526.125 13595.737 13819.798 1543.4051
## 27 Oceania 1970 16046.0373 18334.198 16850.645 16511.174 988.2239
## 28 Oceania 1980 17632.4104 21888.889 19501.375 19242.100 1416.4832
## 29 Oceania 1990 18363.3249 26997.937 22459.111 22237.590 3939.4177
## 30 Oceania 2000 23189.8014 34435.367 28374.483 27936.382 6938.4507
The highest GDP per capita lies in developed countries, and their changes a smaller than Asia. But Asia has a great increase by decades.
I used several functions to form two tables, one is for the changes of life expectancy by continents by decade, and another is the changes of GDP per capita by continent by decades. And those two tables illustrated 5 statsitics for each decade and continent. We could see the increaseing tendency of changing of life expectancy from those continents, especially Asia. And the great increasing in GDP in Asia too.
I tried to analysis the 5 decades the life expectancy and the gdp per capita, first time I just used subset to five indiviual continent and use the aggregate function tried to calculate the answer, but the only things that i can find is the averge answer durning the whole time and I stuck in every decades, so I used another way tried to find the relation durning the plots. for each question I created 5*5 plots. 5 contients and 5 decedes, and from the graphs that I got, it is really easy to conclude that the life expectancy and the cgp per capita increase when the years increase.
data_by_decade<- function(dataset){
dataset$decade <- cut(dataset$year, seq(1950,2010,10),labels = as.character(seq(1950,2000,10)))
return(dataset)
}
fun_continents <- function(continent, decade) {
a <- gapminder[which(gapminder$continent == continent & gapminder$decade == decade),]
stats <- c(min = min(a$lifeExp), max =max( a$lifeExp),
mean = mean(a$lifeExp), median = median(a$lifeExp),
IQR = quantile(a$lifeExp, 0.75) - quantile(a$lifeExp, 0.25))
return(stats)
}
fun_continents( "Africa", 1950)
## min max mean median IQR.75%
## 30.00000 58.08900 40.20092 39.98900 6.51375
gapminder <- data_by_decade(gapminder)
continentdata <- c()
sta <- c()
for(continent in levels(gapminder$continent)) {
for(decade in levels(gapminder$decade)) {
continentdata <- rbind(continentdata, c(continent, decade))
sta <- rbind(sta, fun_continents(continent, decade ))
}
}
continentdata
## [,1] [,2]
## [1,] "Africa" "1950"
## [2,] "Africa" "1960"
## [3,] "Africa" "1970"
## [4,] "Africa" "1980"
## [5,] "Africa" "1990"
## [6,] "Africa" "2000"
## [7,] "Americas" "1950"
## [8,] "Americas" "1960"
## [9,] "Americas" "1970"
## [10,] "Americas" "1980"
## [11,] "Americas" "1990"
## [12,] "Americas" "2000"
## [13,] "Asia" "1950"
## [14,] "Asia" "1960"
## [15,] "Asia" "1970"
## [16,] "Asia" "1980"
## [17,] "Asia" "1990"
## [18,] "Asia" "2000"
## [19,] "Europe" "1950"
## [20,] "Europe" "1960"
## [21,] "Europe" "1970"
## [22,] "Europe" "1980"
## [23,] "Europe" "1990"
## [24,] "Europe" "2000"
## [25,] "Oceania" "1950"
## [26,] "Oceania" "1960"
## [27,] "Oceania" "1970"
## [28,] "Oceania" "1980"
## [29,] "Oceania" "1990"
## [30,] "Oceania" "2000"
sta
## min max mean median IQR.75%
## [1,] 30.000 58.089 40.20092 39.9890 6.51375
## [2,] 32.767 61.557 44.32699 43.9890 7.95300
## [3,] 35.400 67.064 48.51568 48.1205 9.14750
## [4,] 38.445 71.913 52.46883 51.5220 11.47125
## [5,] 23.599 74.772 53.61392 52.6000 12.32125
## [6,] 39.193 76.442 54.06563 52.4060 11.90725
## [7,] 37.579 69.960 54.62006 55.1540 16.43325
## [8,] 43.428 72.130 59.40484 60.3165 12.82300
## [9,] 46.714 74.210 63.39324 65.3720 10.41200
## [10,] 51.461 76.860 67.15978 68.1625 8.27450
## [11,] 55.089 78.610 70.35942 70.7315 5.60250
## [12,] 58.137 80.653 73.01508 72.8275 5.56150
## [13,] 28.801 67.840 47.81647 45.7770 13.72900
## [14,] 31.997 71.430 53.11343 51.6300 14.01075
## [15,] 31.220 75.380 58.46491 59.3750 12.13875
## [16,] 39.854 78.670 63.73456 64.8205 10.69550
## [17,] 41.674 80.690 67.27886 69.0085 10.77300
## [18,] 42.129 82.603 69.98118 71.6570 9.87675
## [19,] 43.585 73.470 65.55578 66.8350 7.47875
## [20,] 52.098 74.160 69.13842 70.0200 3.61550
## [21,] 57.005 76.110 71.35640 71.1400 3.17500
## [22,] 61.036 77.410 73.22428 74.0500 4.40500
## [23,] 66.146 79.390 74.97263 75.8350 4.97725
## [24,] 70.845 81.757 77.17460 78.1770 4.84150
## [25,] 69.120 70.330 69.77500 69.8250 0.95500
## [26,] 70.930 71.520 71.19750 71.1700 0.25250
## [27,] 71.890 73.490 72.38250 72.0750 0.61750
## [28,] 73.840 76.320 74.80500 74.5300 0.93500
## [29,] 76.330 78.830 77.56750 77.5550 0.63250
## [30,] 79.110 81.235 80.22975 80.2870 0.65575
s <- data.frame(continentdata, sta )
names(s)[1] <- "continent"
names(s)[2] <- "decade"
s
## continent decade min max mean median IQR.75.
## 1 Africa 1950 30.000 58.089 40.20092 39.9890 6.51375
## 2 Africa 1960 32.767 61.557 44.32699 43.9890 7.95300
## 3 Africa 1970 35.400 67.064 48.51568 48.1205 9.14750
## 4 Africa 1980 38.445 71.913 52.46883 51.5220 11.47125
## 5 Africa 1990 23.599 74.772 53.61392 52.6000 12.32125
## 6 Africa 2000 39.193 76.442 54.06563 52.4060 11.90725
## 7 Americas 1950 37.579 69.960 54.62006 55.1540 16.43325
## 8 Americas 1960 43.428 72.130 59.40484 60.3165 12.82300
## 9 Americas 1970 46.714 74.210 63.39324 65.3720 10.41200
## 10 Americas 1980 51.461 76.860 67.15978 68.1625 8.27450
## 11 Americas 1990 55.089 78.610 70.35942 70.7315 5.60250
## 12 Americas 2000 58.137 80.653 73.01508 72.8275 5.56150
## 13 Asia 1950 28.801 67.840 47.81647 45.7770 13.72900
## 14 Asia 1960 31.997 71.430 53.11343 51.6300 14.01075
## 15 Asia 1970 31.220 75.380 58.46491 59.3750 12.13875
## 16 Asia 1980 39.854 78.670 63.73456 64.8205 10.69550
## 17 Asia 1990 41.674 80.690 67.27886 69.0085 10.77300
## 18 Asia 2000 42.129 82.603 69.98118 71.6570 9.87675
## 19 Europe 1950 43.585 73.470 65.55578 66.8350 7.47875
## 20 Europe 1960 52.098 74.160 69.13842 70.0200 3.61550
## 21 Europe 1970 57.005 76.110 71.35640 71.1400 3.17500
## 22 Europe 1980 61.036 77.410 73.22428 74.0500 4.40500
## 23 Europe 1990 66.146 79.390 74.97263 75.8350 4.97725
## 24 Europe 2000 70.845 81.757 77.17460 78.1770 4.84150
## 25 Oceania 1950 69.120 70.330 69.77500 69.8250 0.95500
## 26 Oceania 1960 70.930 71.520 71.19750 71.1700 0.25250
## 27 Oceania 1970 71.890 73.490 72.38250 72.0750 0.61750
## 28 Oceania 1980 73.840 76.320 74.80500 74.5300 0.93500
## 29 Oceania 1990 76.330 78.830 77.56750 77.5550 0.63250
## 30 Oceania 2000 79.110 81.235 80.22975 80.2870 0.65575
From the table, we can see the life expectancy is increasing by decades for each continent. But the IQR for developing countries, like in Asia increase first and then decrease a littel bit. And for Europe and Americas, the IQR doesn’t change a lot, it’s steady.
fun_gdp <- function(continent, decade) {
a <- gapminder[which(gapminder$continent == continent & gapminder$decade == decade),]
stats2 <- c(min = min(a$gdpPercap), max =max( a$gdpPercap),
mean = mean(a$gdpPercap), median = median(a$gdpPercap),
IQR = quantile(a$gdpPercap, 0.75) - quantile(a$gdpPercap, 0.25))
return(stats2)
}
fun_gdp("Africa",1950)
## min max mean median IQR.75%
## 298.8462 5487.1042 1318.9043 1024.0230 950.0916
gap <- data_by_decade(gapminder)
continentgdp <- c()
sta2<- c()
for(continent in levels(gap$continent)) {
for(decade in levels(gap$decade)) {
continentgdp <- rbind(continentgdp, c(continent, decade))
sta2 <- rbind(sta2, fun_gdp(continent, decade ))
}
}
continentgdp
## [,1] [,2]
## [1,] "Africa" "1950"
## [2,] "Africa" "1960"
## [3,] "Africa" "1970"
## [4,] "Africa" "1980"
## [5,] "Africa" "1990"
## [6,] "Africa" "2000"
## [7,] "Americas" "1950"
## [8,] "Americas" "1960"
## [9,] "Americas" "1970"
## [10,] "Americas" "1980"
## [11,] "Americas" "1990"
## [12,] "Americas" "2000"
## [13,] "Asia" "1950"
## [14,] "Asia" "1960"
## [15,] "Asia" "1970"
## [16,] "Asia" "1980"
## [17,] "Asia" "1990"
## [18,] "Asia" "2000"
## [19,] "Europe" "1950"
## [20,] "Europe" "1960"
## [21,] "Europe" "1970"
## [22,] "Europe" "1980"
## [23,] "Europe" "1990"
## [24,] "Europe" "2000"
## [25,] "Oceania" "1950"
## [26,] "Oceania" "1960"
## [27,] "Oceania" "1970"
## [28,] "Oceania" "1980"
## [29,] "Oceania" "1990"
## [30,] "Oceania" "2000"
sta2
## min max mean median IQR.75%
## [1,] 298.8462 5487.104 1318.904 1024.023 950.0916
## [2,] 355.2032 18772.752 1824.221 1191.555 1104.8081
## [3,] 464.0995 21951.212 2462.777 1402.376 1724.7493
## [4,] 389.8762 17364.275 2382.131 1286.173 1983.9259
## [5,] 312.1884 14722.842 2330.285 1179.883 2069.0063
## [6,] 241.1659 13206.485 2844.209 1307.562 2826.6352
## [7,] 1397.7171 14847.127 4347.553 3266.944 2205.0266
## [8,] 1452.0577 19530.366 5284.898 4549.084 2799.6370
## [9,] 1654.4569 24072.632 6921.671 5490.198 3124.1509
## [10,] 1823.0160 29884.350 7650.069 6397.723 4300.9379
## [11,] 1341.7269 35767.433 8467.118 6813.664 4848.2282
## [12,] 1201.6372 42951.653 10145.354 7382.469 5542.2684
## [13,] 331.0000 113523.133 5491.608 1497.727 2297.9368
## [14,] 349.0000 95458.112 5850.271 1852.401 4085.0329
## [15,] 357.0000 109347.867 7989.391 2850.723 8539.1421
## [16,] 385.0000 33693.175 7521.181 4106.509 11165.1958
## [17,] 347.0000 40300.620 9236.892 3685.722 15728.0982
## [18,] 611.0000 47306.990 11323.559 4287.633 18938.5251
## [19,] 973.5332 17909.490 6312.035 5730.677 4956.2819
## [20,] 1709.6837 22966.144 9254.655 8463.000 6811.9320
## [21,] 2860.1698 27195.113 13381.777 13044.562 8352.9485
## [22,] 3630.8807 31540.975 16416.104 15995.703 9922.0911
## [23,] 2497.4379 41283.164 18069.175 18122.048 16830.2216
## [24,] 4604.2117 49357.190 23383.107 26653.335 20705.2445
## [25,] 10039.5956 12247.395 10948.304 10753.113 846.7554
## [26,] 12217.2269 14526.125 13595.737 13819.798 1543.4051
## [27,] 16046.0373 18334.198 16850.645 16511.174 988.2239
## [28,] 17632.4104 21888.889 19501.375 19242.100 1416.4832
## [29,] 18363.3249 26997.937 22459.111 22237.590 3939.4177
## [30,] 23189.8014 34435.367 28374.483 27936.382 6938.4507
s2 <- data.frame(continentgdp,sta2)
names(s2)[1] <- "continent"
names(s2)[2] <- "decade"
s2
## continent decade min max mean median IQR.75.
## 1 Africa 1950 298.8462 5487.104 1318.904 1024.023 950.0916
## 2 Africa 1960 355.2032 18772.752 1824.221 1191.555 1104.8081
## 3 Africa 1970 464.0995 21951.212 2462.777 1402.376 1724.7493
## 4 Africa 1980 389.8762 17364.275 2382.131 1286.173 1983.9259
## 5 Africa 1990 312.1884 14722.842 2330.285 1179.883 2069.0063
## 6 Africa 2000 241.1659 13206.485 2844.209 1307.562 2826.6352
## 7 Americas 1950 1397.7171 14847.127 4347.553 3266.944 2205.0266
## 8 Americas 1960 1452.0577 19530.366 5284.898 4549.084 2799.6370
## 9 Americas 1970 1654.4569 24072.632 6921.671 5490.198 3124.1509
## 10 Americas 1980 1823.0160 29884.350 7650.069 6397.723 4300.9379
## 11 Americas 1990 1341.7269 35767.433 8467.118 6813.664 4848.2282
## 12 Americas 2000 1201.6372 42951.653 10145.354 7382.469 5542.2684
## 13 Asia 1950 331.0000 113523.133 5491.608 1497.727 2297.9368
## 14 Asia 1960 349.0000 95458.112 5850.271 1852.401 4085.0329
## 15 Asia 1970 357.0000 109347.867 7989.391 2850.723 8539.1421
## 16 Asia 1980 385.0000 33693.175 7521.181 4106.509 11165.1958
## 17 Asia 1990 347.0000 40300.620 9236.892 3685.722 15728.0982
## 18 Asia 2000 611.0000 47306.990 11323.559 4287.633 18938.5251
## 19 Europe 1950 973.5332 17909.490 6312.035 5730.677 4956.2819
## 20 Europe 1960 1709.6837 22966.144 9254.655 8463.000 6811.9320
## 21 Europe 1970 2860.1698 27195.113 13381.777 13044.562 8352.9485
## 22 Europe 1980 3630.8807 31540.975 16416.104 15995.703 9922.0911
## 23 Europe 1990 2497.4379 41283.164 18069.175 18122.048 16830.2216
## 24 Europe 2000 4604.2117 49357.190 23383.107 26653.335 20705.2445
## 25 Oceania 1950 10039.5956 12247.395 10948.304 10753.113 846.7554
## 26 Oceania 1960 12217.2269 14526.125 13595.737 13819.798 1543.4051
## 27 Oceania 1970 16046.0373 18334.198 16850.645 16511.174 988.2239
## 28 Oceania 1980 17632.4104 21888.889 19501.375 19242.100 1416.4832
## 29 Oceania 1990 18363.3249 26997.937 22459.111 22237.590 3939.4177
## 30 Oceania 2000 23189.8014 34435.367 28374.483 27936.382 6938.4507
The highest GDP per capita lies in developed countries, and their changes a smaller than Asia. But Asia has a great increase by decades.
Europe <- subset(gapminder, continent == "Europe")
Africa <- subset(gapminder, continent == "Africa")
Asia <- subset(gapminder, continent == "Asia")
Americas <- subset(gapminder, continent == "Americas")
Oceania <- subset(gapminder, continent == "Oceania")
aggregate(lifeExp~continent, gapminder, min)
## continent lifeExp
## 1 Africa 23.599
## 2 Americas 37.579
## 3 Asia 28.801
## 4 Europe 43.585
## 5 Oceania 69.120
aggregate(lifeExp~continent, gapminder, max)
## continent lifeExp
## 1 Africa 76.442
## 2 Americas 80.653
## 3 Asia 82.603
## 4 Europe 81.757
## 5 Oceania 81.235
aggregate(lifeExp~continent, gapminder, mean)
## continent lifeExp
## 1 Africa 48.86533
## 2 Americas 64.65874
## 3 Asia 60.06490
## 4 Europe 71.90369
## 5 Oceania 74.32621
aggregate(lifeExp~continent, gapminder, median)
## continent lifeExp
## 1 Africa 47.7920
## 2 Americas 67.0480
## 3 Asia 61.7915
## 4 Europe 72.2410
## 5 Oceania 73.6650
aggregate(lifeExp~continent, gapminder, IQR)
## continent lifeExp
## 1 Africa 12.0390
## 2 Americas 13.2895
## 3 Asia 18.0790
## 4 Europe 5.8805
## 5 Oceania 6.3475
filter(gapminder,(continent=="Europe" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Europe" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Europe" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Europe" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Europe" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Africa" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Africa" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Africa" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Africa" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Africa" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Asia" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Asia" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Asia" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Asia" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Asia" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Americas" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Americas" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Americas" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Americas" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Americas" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=lifeExp),binwidth=1)
europe <- subset(gapminder, continent == "Europe")
africa <- subset(gapminder, continent == "Africa")
asia <- subset(gapminder, continent == "Asia")
americas <- subset(gapminder, continent == "Americas")
oceania <- subset(gapminder, continent == "Oceania")
aggregate(gdpPercap~continent, gapminder, min)
## continent gdpPercap
## 1 Africa 241.1659
## 2 Americas 1201.6372
## 3 Asia 331.0000
## 4 Europe 973.5332
## 5 Oceania 10039.5956
aggregate(gdpPercap~continent, gapminder, max)
## continent gdpPercap
## 1 Africa 21951.21
## 2 Americas 42951.65
## 3 Asia 113523.13
## 4 Europe 49357.19
## 5 Oceania 34435.37
aggregate(gdpPercap~continent, gapminder, mean)
## continent gdpPercap
## 1 Africa 2193.755
## 2 Americas 7136.110
## 3 Asia 7902.150
## 4 Europe 14469.476
## 5 Oceania 18621.609
aggregate(gdpPercap~continent, gapminder, median)
## continent gdpPercap
## 1 Africa 1192.138
## 2 Americas 5465.510
## 3 Asia 2646.787
## 4 Europe 12081.749
## 5 Oceania 17983.304
aggregate(gdpPercap~continent, gapminder, IQR)
## continent gdpPercap
## 1 Africa 1616.170
## 2 Americas 4402.431
## 3 Asia 7492.262
## 4 Europe 13248.301
## 5 Oceania 8072.258
filter(gapminder,(continent=="Europe" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Europe" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Europe" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Europe" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Europe" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Africa" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Africa" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Africa" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Africa" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Africa" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Asia" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Asia" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Asia" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Asia" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Asia" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Americas" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Americas" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Americas" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Americas" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Americas" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<1970 & year >= 1960)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<1980 & year >= 1970)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<1990 & year >= 1980)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<2000 & year >= 1990)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)
filter(gapminder,(continent=="Oceania" & year<2010 & year >= 2000)) %>%
ggplot() +
geom_freqpoly(aes(x=gdpPercap),binwidth=1)